package cn.thoughtworks.school.response;

import cn.thoughtworks.school.entities.Serial;
import com.fasterxml.jackson.annotation.JsonFormat;
import lombok.*;

import java.util.Date;
import java.util.Map;

@Setter
@Getter
@NoArgsConstructor
@AllArgsConstructor
@Builder
public class SimpleSerialResponse {
  private Long id;
  private String coverUrl;
  private String title;
  private String description;
  private Boolean isPublic;
  private String username;
  private Integer count;
  @JsonFormat(pattern = "yyyy-MM-dd", timezone = "GMT+8")
  private Date createTime;

  public static SimpleSerialResponse build(Map user, Serial serial) {
    return SimpleSerialResponse.builder()
      .id(serial.getId())
      .coverUrl(serial.getCoverUrl())
      .title(serial.getTitle())
      .description(serial.getDescription())
      .isPublic(serial.getIsPublic())
      .createTime(serial.getCreateTime())
      .count(serial.getVideos().size())
      .username(user.get("name").toString())
      .build();
  }
}
